package com.itgo.codegen.util;

import org.apache.commons.lang.StringUtils;

public class StringLang {

	public static String tfRule( String fieldName ){
		if( StringUtils.isEmpty( fieldName ) ) {
			return null ;
		}
		fieldName = fieldName.toLowerCase() ;
		boolean nextUpper = false ;
		StringBuilder tfName = new StringBuilder() ;
		for( int i = 0 ; i < fieldName.length() ; i ++ ){
			String chars = fieldName.charAt( i )+ "" ;
			if( chars.equals("_") ){
				nextUpper = true ;
				continue ;
			}
			if( nextUpper ){
				tfName.append( chars.toUpperCase() ) ;
			}else{
				tfName.append( chars ) ;
			}
			nextUpper = false ;
		}
		return tfName.toString() ;
	}
	
	public static String trim( String str , String start , String end ){
		if( StringUtils.isEmpty( str ) ){
			return str ;
		}
		str = str.trim() ;
		if( start != null && str.startsWith( start ) ){
			str = str.substring( start.length() ) ;
		}
		if( end != null && str.endsWith( end ) ){
			str = str.substring(0 , str.length() - end.length() ) ;
		}
		return str ;
	}
	
	public static String setMethodName( String field ){
		String method = "set" ;
		method += (field.charAt(0)+"").toUpperCase() + field.substring(1) ;
		return method ;
	}
	
	public static String getMethodName( String field ){
		String method = "get" ;
		method += (field.charAt(0)+"").toUpperCase() + field.substring(1) ;
		return method ;
	}
	
	public static String lover( String text ){
		return text.toLowerCase() ;
	}
	
	public static String toUpper( String text ){
		return text.toUpperCase() ;
	}
	
	public static String aUpper( String text ){
		String lover = lover( text ) ;
		return lover.replace( String.valueOf(lover.charAt(0)) , toUpper( String.valueOf(lover.charAt(0)) ) ) ;
	}
	
	public static String au( String text ){
		return text.replace( String.valueOf(text.charAt(0)) , toUpper( String.valueOf(text.charAt(0)) ) ) ;
	}
	
	public static String al( String text ){
		return text.replace( String.valueOf(text.charAt(0)) , lover( String.valueOf(text.charAt(0)) ) ) ;
	}
	
}
